package org.eddm.rule;

import java.util.ArrayList;
import java.util.List;

import org.eddm.metamodel.Metamodel;
import org.eddm.metamodel.Metamodels;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class RElement 
{
	public String _id      = "?";
	
	public List<String> _ltSource;
	public List<String> _ltTarget;
	public int   _max      = 0;
	public int   _min      = 0;
	public int _count      = 0;
	
	public RElement()
	{
		_ltSource = new ArrayList<String>();
		_ltTarget = new ArrayList<String>();
	}
	
	public void setMElement(String mElementName)
	{
		Metamodel metamodel = Metamodels.getMetamodel();
		
	}
	
	public void setMinMaxRules(Element element, Rule rule)
	{		
		String maxAux = element.getAttribute("max");
		String minAux = element.getAttribute("min");
				
		
		if((maxAux != null) && ( !maxAux.equals("")) )
		{
			_max = Integer.parseInt(maxAux);
		}
		if((minAux != null) && ( !minAux.equals("")) )
		{
			_min = Integer.parseInt(minAux);
		}
				
	}
	
	public void setSourceNodes(Element elemSource)
	{
		try
		{			
			// Teste if the target list is null
						
			
			// Get the tag <element> inside the tag <target>
			NodeList nlElement = elemSource.getElementsByTagName("element");
			for( int i=0; i<nlElement.getLength(); i++ ) 
		    { 
				Element eleAux = (Element) nlElement.item( i );
				this._ltSource.add( eleAux.getAttribute("id") );
		    }
			
			
		}
		catch(Exception ex)
		{
			System.out.println( "setSourceNodes:: error XML >> "+ ex.toString() );
		}
		
	}
	
	public void setTargetNodes(Element elemTarget)
	{
		//TODO: Pegar a tag <element> e tratar o caso de vazio // Caso vazio em analise
		//TODO: Tratar a tag <Condition> 
		
		try
		{			
			// Teste if the target list is null
			
			
			
			// Get the tag <element> inside the tag <target>
			NodeList nlElement = elemTarget.getElementsByTagName("element");
			for( int i=0; i<nlElement.getLength(); i++ ) 
		    { 
				Element eleAux = (Element) nlElement.item( i );
				this._ltTarget.add( eleAux.getAttribute("id") );
		    }
			
			
		}
		catch(Exception ex)
		{
			System.out.println( "setTargetNodes:: error XML >> " + ex.toString() );
		}
		
	}
	
}
